package se.sics.drsm.simulation;

import java.util.Random;

import se.sics.kompics.network.Message;
import se.sics.kompics.network.model.common.NetworkModel;
import se.sics.kompics.p2p.experiment.dsl.distribution.LongExponentialDistribution;

/**
 * The <code>SimplifiedNetworkModel</code> class.
 *
 * @author Shadid Chowdhury <msrch@kth.se>
 */
public class SimplifiedNetworkModel implements NetworkModel {

    private final Random random;

    private final LongExponentialDistribution distribution;

    /**
     * Instantiates a SimplifiedNetworkModel
     *
     * @param seed seed for Random class
     * @param mean mean of exponential distribution
     */
    public SimplifiedNetworkModel(long seed, long mean) {
        random = new Random(seed);
        distribution = new LongExponentialDistribution(mean, random);
    }

    /* (non-Javadoc)
     * @see se.sics.kompics.network.model.common.NetworkModel#getLatencyMs(se.sics.kompics.network.Message)
     */
    public long getLatencyMs(Message message) {
        long latency;
        latency = distribution.draw() * (random.nextInt(10) + 1);

        if (latency > 1200) {
            latency = 1200;
        }
        return latency;

        // TODO: for data item we need this kind of higher latency
        // if (message instanceof DataItems) {
        // latency *= (random.nextInt(100) + 1);
        //
        // if (latency > 30000) {
        // latency = 30000;
        // }
        // }

    }
}
